package com.ikun.admin.modules.auth.eneity;


import com.ikun.common.entity.AppUserInfo;
import com.ikun.common.entity.SecurityUserInfo;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author ximeng
 * @title: SecurityUser
 */
@Component
@Data
public class SecurityUser implements UserDetails {

    //管理端登陆的用户对象信息
    private SecurityUserInfo userInfo;

    //管理端角色和权限信息
    private List<String> roleAndPerms;

    //app端登陆的用户对象信息
    private AppUserInfo appUserInfo;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        List<GrantedAuthority> grantedAuthorityList = new ArrayList<>();
        for (int i = 0; i < roleAndPerms.size(); i++) {
            grantedAuthorityList.add(new SimpleGrantedAuthority(roleAndPerms.get(i)));
        }
        return grantedAuthorityList;
    }

    @Override
    public String getPassword() {
        return userInfo.getPassword();
    }

    @Override
    public String getUsername() {
        return userInfo.getUsername();
    }

    //账号是否过期
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    //账号是否被锁定
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }
    //账号是否有资质

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    //账号是否可用
    @Override
    public boolean isEnabled() {
        return true;
    }
}
